home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / mimelib / binhex.h < prev    next >
Encoding:
C/C++ Source or Header  |  2007-05-14  |  6.4 KB  |  160 lines

  1. //=============================================================================
  2. // File:       binhex.h
  3. // Contents:   Declarations for DwBinhex
  4. // Maintainer: Doug Sauder <dwsauder@fwb.gulf.net>
  5. // WWW:        http://www.fwb.gulf.net/~dwsauder/mimepp.html
  6. //
  7. // Copyright (c) 1996, 1997 Douglas W. Sauder
  8. // All rights reserved.
  9. // 
  10. // IN NO EVENT SHALL DOUGLAS W. SAUDER BE LIABLE TO ANY PARTY FOR DIRECT,
  11. // INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF
  12. // THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF DOUGLAS W. SAUDER
  13. // HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  14. //
  15. // DOUGLAS W. SAUDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT
  16. // NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
  17. // PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS"
  18. // BASIS, AND DOUGLAS W. SAUDER HAS NO OBLIGATION TO PROVIDE MAINTENANCE,
  19. // SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
  20. //
  21. //=============================================================================
  22.  
  23. #ifndef DW_BINHEX_H
  24. #define DW_BINHEX_H
  25.  
  26. #ifndef DW_CONFIG_H
  27. #include <mimelib/config.h>
  28. #endif
  29.  
  30. #ifndef DW_STRING_H
  31. #include <mimelib/string.h>
  32. #endif
  33.  
  34. //=============================================================================
  35. //+ Name DwBinhex -- Class for converting files to or from Binhex 4.0 format
  36. //+ Description
  37. //. {\tt DwBinhex} converts data to or from Binhex 4.0 format.  Binhex is a
  38. //. format used almost exclusively on Macintosh computers for encoding
  39. //. files into text characters for transmission through the mail transport
  40. //. system or for archiving on non-Macintosh systems.  The format includes
  41. //. the file name, file type, file creator, Macintosh Finder flags, data fork,
  42. //. resource fork, and checksums. In MIME, the use of Binhex is deprecated;
  43. //. applesingle and appledouble are the preferred format for encoding
  44. //. Macintosh files.  The Binhex 4.0 format is described in RFC-1741.
  45. //. Binhex is a widely used, {\it de facto} standard, but it is not an
  46. //. official Internet standard.
  47. //.
  48. //. To use {\tt DwBinhex} for converting a Macintosh file to Binex format,
  49. //. call the member functions {\tt SetFileName()}, {\tt SetFileType()},
  50. //. {\tt SetFileCreator()}, {\tt SetFlag1()}, {\tt SetFlag2()},
  51. //. {\tt SetDataFork()}, and {\tt SetResourceFork()} to set the elements
  52. //. to be encoded.  Any elements that are not set by calling one of the
  53. //. member functions are assigned reasonable defaults.  Then call the
  54. //. {\tt Encode()} member function to actually perform the conversion to
  55. //. Binhex.  Finally, call {\tt BinhexChars()} to retrieve the Binhex
  56. //. characters.
  57. //.
  58. //. To use {\tt DwBinhex} for converting a Macintosh file from Binhex format,
  59. //. call the member function {\tt SetBinhexChars()} to assign the Binhex
  60. //. characters to be converted.  Then call {\tt Decode()} to actually
  61. //. perform the conversion.  Finally, call {\tt FileName()}, {\tt FileType()},
  62. //. {\tt FileCreator()}, {\tt Flag1()}, {\tt Flag2()}, {\tt DataFork()},
  63. //. and {\tt ResourceFork()} to extract the decoded elements.
  64. //.
  65. //. Note: {\tt DwBinhex} does not change the file name in any way. When you
  66. //. you are dealing with file names, you should be aware of the fact that
  67. //. some filenames that are valid on a Macintosh may cause problems or
  68. //. unexpected results on a non-Macintosh system, and vice versa.  Such
  69. //. problem characters include slash ('/'), colon (':'), space and possibly
  70. //. other characters.
  71. //=============================================================================
  72. // Last modified 1997-08-25
  73. //+ Noentry ~DwBinhex
  74.  
  75.  
  76. class DW_EXPORT DwBinhex {
  77.  
  78. public:
  79.  
  80.     DwBinhex();
  81.     //. This is the default constructor.
  82.  
  83.     virtual ~DwBinhex();
  84.  
  85.     void Initialize();
  86.     //. Resets the object's internal state to its initial state.  Call
  87.     //. this member function to reuse the object for more than one encode
  88.     //. or decode operation.
  89.  
  90.     const char* FileName() const;
  91.     void SetFileName(const char* aName);
  92.     //. Gets or sets the file name.  The file name is restricted
  93.     //. to a maximum length of 63 characters.
  94.  
  95.     void FileType(char* aBuf) const;
  96.     void SetFileType(const char* aType);
  97.     //. Gets or sets the file type.  All Macintosh files have a file type,
  98.     //. which is represented by four bytes.  Some examples include "TEXT"
  99.     //. for a text file, or "APPL" for an application.  {\tt aBuf} should
  100.     //. point to an array of at least four characters.
  101.  
  102.     void FileCreator(char* aBuf) const;
  103.     void SetFileCreator(const char* aType);
  104.     //. Gets or sets the file creator.  Most Macintosh files have a creator,
  105.     //. which is represented by a signature of four bytes.  The creator
  106.     //. specifies which application to launch when a file's icon is double
  107.     //. clicked.  {\tt aBuf} should point to an array of at least four
  108.     //. characters.
  109.  
  110.     DwUint8 Flag1() const;
  111.     void SetFlag1(DwUint8 aFlag);
  112.     //. Gets or sets the first byte of the Macintosh Finder flags.  For
  113.     //. files that originate on non-Macintosh systems, this byte should
  114.     //. be set to zero (the default).
  115.  
  116.     DwUint8 Flag2() const;
  117.     void SetFlag2(DwUint8 aFlag);
  118.     //. Gets or sets the second byte of the Macintosh Finder flags.  For
  119.     //. files that originate on non-Macintosh systems, this byte should
  120.     //. be set to zero (the default).
  121.  
  122.     const DwString& DataFork() const;
  123.     void SetDataFork(const DwString& aStr);
  124.     //. Gets or sets the data fork for the file.  For files that originate
  125.     //. on non-Macintosh systems, such as a GIF or JPEG file, the file data
  126.     //. should be set as the data fork.
  127.  
  128.     const DwString& ResourceFork() const;
  129.     void SetResourceFork(const DwString& aStr);
  130.     //. Gets or sets the resource fork for the file.  For files that originate
  131.     //. on non-Macintosh systems, such as a GIF or JPEG file, the resource
  132.     //. should be normally be empty.
  133.  
  134.     const DwString& BinhexChars() const;
  135.     void SetBinhexChars(const DwString& aStr);
  136.     //. Gets or sets the characters of the Binhex encoded file.
  137.  
  138.     void Encode();
  139.     //. Converts the Macintosh file information to Binhex format.
  140.  
  141.     int Decode();
  142.     //. Converts the Macintosh file information from Binhex format.  Returns
  143.     //. zero if the decode operation completes successufully; otherwise,
  144.     //. the function returns -1.
  145.    
  146. private:
  147.  
  148.     char mFileName[64];
  149.     char mFileType[8];
  150.     char mFileCreator[8];
  151.     DwUint8 mFlag1;
  152.     DwUint8 mFlag2;
  153.     DwString mDataFork;
  154.     DwString mResourceFork;
  155.     DwString mBinhexChars;
  156.  
  157. };
  158.  
  159. #endif
  160.